// 全局类型
type user = struct {
	int id
	string username
	string password
}

// 全局变量(暂时不支持类型自动推导)
int id = 1
[user] list = []
{string:user} userof = {}

// 全局函数
fn register(string username, string password):void! {
	var u = userof[username] catch err {}
    if u.id > 0 {
        throw errorf('The user ' + username +' has already registered')
    }

	u = user{
		id: id,
		username: username,
		password: password,
	}

	list.push(u)
	userof[username] = u
	id += 1
}

fn find(string username):user! {
    var u = userof[username] catch err {}
	if u.id == 0 {
		throw errorf('user ' + username + ' notfound')
	}

	return u
}